<template>
  <div class="header">
    <div class="head">
      <div class="item" v-for="item in swip.slip" :key="item.id">
        <img :src="item.img" alt="">
        <span>{{ item.text }}</span>
      </div>
    </div>
  </div>

  <div class="video" v-for="item in state.videos">
    <img :src="item.img" alt="" :key="item.id">
    <div class="text">
      <div class="introduce">{{ item.title }}</div>
      <div class="author">{{ item.author }}</div>
      <div class="date">
        <span class="number">{{ item.number }}</span>
        <span>{{ item.date }}</span>
        <span class="icon">:</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import useCounter from '../../store/counter';
import { onBeforeMount } from 'vue';
import axios from '../../api/index.js'
import { reactive } from 'vue';
const state = reactive({
  videos:[]
})
const swip = useCounter()

onBeforeMount(
  async () => {
    const res = await axios.post('/recommend')
    state.videos = res.data
  }
)
</script>

<style lang="less" scoped>
.header {
  overflow: hidden;
  position: relative;
  height: 1.6rem;
  width: 100%;
}

.head {
  overflow-x: scroll;
  height: 1.6rem;
  display: flex;
  position: relative;
  padding: 0.2rem 0;

  .item {
    margin: 0 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;

    img {
      border-radius: 50%;
      width: 0.8rem;
      height: 0.8rem;
    }

    span {
      padding: 0.15rem;
      font-size: 0.3rem;
      white-space: nowrap;
    }
  }
}

.video {
  left: 5%;
  width: 95%;
  padding-top: 0.15rem;
  position: relative;
  display: flex;
  border-bottom: 1px solid #ccc;

  img {
    width: 4rem;
    height: 2.25rem;
    border-radius: 0.1rem;
  }

  .text {
    flex: 1;
    padding: 0.15rem;

    .introduce {
      font-size: 0.4rem;
      height: 1rem;
    }

    .author,
    .date {
      padding: 0.15rem 0;
      font-size: 0.36rem;
      color: #000;
    }

    .date {
      position: relative;
      display: flex;
      align-items: center;

      .icon {
        position: absolute;
        right: 0.1rem;
      }

      .number {
        margin-right: 0.4rem;
        position: relative;
      }

      .number::after {
        content: '.';
        font-size: 0.5rem;
        position: absolute;
        bottom: 0.1rem;
        right: -0.3rem;
      }
    }
  }

}
</style>